<!DOCTYPE html>
<html lang="en"xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <title>首页</title>
    <script  src="../../static/layui/layui.js" data-th-src="@{/layui/layui.js}"></script>
    <link rel="stylesheet"  data-th-href="@{/layui/css/layui.css}" href="../../static/layui/css/layui.css" >
    <style>

        .layui-breadcrumb{
            line-height: 30px;
        }
    </style>
</head>
<body>
<form id="form1" method="post" class="layui-form" data-th-action="@{insertActivation/insert}" enctype="multipart/form-data">
    <div class="layui-form-item">
        <label class="layui-form-label">激活码：</label>
        <div class="layui-input-inline">
            <input type="text" name="coName" id="coName" onblur="verify()" required  lay-verify="required" placeholder="请输入激活码" autocomplete="off" class="layui-input">
        </div>
        <div id="u1" style="display: inline"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>

<table class="layui-hide" id="show"></table>

<script data-th-inline="javascript">
    layui.use(["table","layer","jquery","element","form"], function(){
        let {table,layer,$,form} = layui; //解构
        table.render({
            elem: '#show'
            ,url:/*[[@{/insertActivation}]]*/
            ,cellMinWidth: 80
            ,page:true
            ,cols: [
                [
                {field:'acId', width:80, title: 'ID'}
                ,{field:'acCode', width:100, title: '激活码'}
                ,{field:'acType', title: '状态（0为未使用1为已使用）'}
                ]
            ]

        });
    });
</script>



<script type="text/javascript">

    function verify() {
        var code = document.getElementById("coName");
        var codeValue = code.value;
        alert(codeValue);
        $.ajax({
            type:'GET',
            url:"/insertActivation/verify/"+codeValue,
            success: function (data) {
                alert("进入ajax")
                let msg =data[0].msg;
                let type1=data[0].type;
                alert(msg);
                if(type1 == 0){
                    document.getElementById("u1").innerHTML = "<font color='red' >"+msg+"</font>";
                    document.getElementById("button1").setAttribute('disabled','true');
                }else{
                    document.getElementById("u1").innerHTML = "<font color='green' >"+msg+"</font>";
                    document.getElementById("button1").removeAttribute('disabled');
                }
            },
            dataType: 'json',
        });
    }
</script>

<script type="text/javascript" data-th-src="@{/js/jquery-3.5.1.js}" src="../../static/js/jquery-3.5.1.js"></script>

</body>
</html>